# coding utf-8
from Software_Set_UI import Ui_MainWindow
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QToolButton, QSizePolicy, QPushButton, \
    QGroupBox, QGridLayout
from PyQt5.QtGui import QIcon, QFont, QPixmap
from PyQt5.QtCore import QPoint, QRect, QSize, Qt  # , pyqtSignal
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets, QtCore
from PyQt5 import QtGui
# PySide2
# PyQt5
import sys
import os
from os import environ, listdir, makedirs, pathsep, startfile
# from PyQt5 import QtCore, QtGui, QtWidgets
import json

import xml.dom.minidom

class mainWindow(Ui_MainWindow, QMainWindow):
    ProjecinfoPath = 'H:/QL_tool_file/Window_Tool/Logical File/SoftwareStarter/Projecinfo/'
    def __init__(self):
        super(mainWindow, self).__init__()
        self.setupUi(self)
        self.Project_WidgetItem_import()
        self.Button_Clicked()
        self.line_edit_list = []
        
        self.Project_Set_listWidget.itemSelectionChanged.connect(lambda *args: self.on_selection_changed()) 

    ##按钮激活
    def Button_Clicked(self):
        ###设置按钮
        self.Project_Set_Bar.clicked.connect(self.__Project_Set_Visible)
        self.Project_Modile_Bar.clicked.connect(self.__Project_Modile_Visible)
        self.Shot_Set_Bar.clicked.connect(self.__Shot_Set_Visible)
        self.Launcher_Settings_Bar.clicked.connect(self.__Launcher_Settings_Visible)
        self.Project_Save.clicked.connect(self.__Project_Save_File)
        ###新建--删除
        self.Project_New.clicked.connect(self.__Project_New)
        self.Project_Del.clicked.connect(self.__Project_Del)

        self.NewModile_Button.clicked.connect(self.__New_Modile_lineEdit)
      
    #项目选择列表
    def Project_WidgetItem_import(self):
        for i in os.listdir(self.ProjecinfoPath):  # 循环读取路径下的文件并筛选输出
            print(i.split(".")[0])
            
            new_item = QListWidgetItem(i.split(".")[0])
            new_item.setSizeHint(QtCore.QSize(180, 50))  # 设置按钮的高度为40
            font = new_item.font()
            font.setPointSize(14)  # 设置字体大小为14
            new_item.setFont(font)
            self.Project_Set_listWidget.addItem(new_item)
        
    #选择项目读取配置信息
    def on_selection_changed(self):
        

        selected_items = self.Project_Set_listWidget.selectedItems()
        for item in selected_items:
            with open(self.ProjecinfoPath + item.text() +'.json', 'r', encoding='utf8') as fp:
                json_data = json.load(fp)  # 读取json文件
                self.Project_en_lineEdit.setText(json_data["Project_set"]["Project_en"])
                self.Project_cn_lineEdit.setText(json_data["Project_set"]["Project_cn"])
                self.Start_Time_lineEdit.setText(json_data["Project_set"]["Start_Time"])
                self.Frame_lineEdit.setText(json_data["Project_set"]["Frame"])
                self.ImageHeight_lineEdit.setText(json_data["Project_set"]["ImageHeight"])
                self.ImageWidth_lineEdit.setText(json_data["Project_set"]["ImageWidth"])
                self.ImageScale_lineEdit.setText(json_data["Project_set"]["ImageScale"])
                self.Project_local_Path_lineEdit.setText(json_data["Project_set"]["Project_local_Path"])
                self.Project_Network_Path_lineEdit.setText(json_data["Project_set"]["Project_Network_Path"])
                self.Project_assets_Path_lineEdit.setText(json_data["Project_set"]["Project_assets_Path"])


                Modile_set = json_data["Modile_set"]
                for Modile in range(len(Modile_set)):
                    self.__New_Modile_lineEdit()
                    self.NewModile_line_edit.setText(Modile_set[Modile]["ModileName"])


                Shot_set = json_data["Shot_set"]
                self.Set_lineEdit.setText(Shot_set["Set"])
                self.Set_Split_lineEdit.setText(Shot_set["Set_Split"])
                self.Events_lineEdit.setText(Shot_set["Events"])
                self.Events_Split_lineEdit.setText(Shot_set["Events_Split"])
                self.Lens_lineEdit.setText(Shot_set["Lens"])
                self.Lens_Split_lineEdit.setText(Shot_set["Lens_Split"])
                self.Class_lineEdit.setText(Shot_set["Class"])
                self.Class_Split_lineEdit.setText(Shot_set["Class_Split"])
                self.Version_lineEdit.setText(Shot_set["Version"])
                self.VersionNumber_lineEdit.setText(Shot_set["VersionNumber"])
                self.FileFormat_lineEdit.setText(Shot_set["FileFormat"])


                Softwares = json_data["Softwares"]
                for Software in Softwares:
                    self.read_Software_info(Software)

        self.New_Software_Button.clicked.connect(lambda *args: self.New_Software())

    
             
    #读取软件信息
    def read_Software_info(self,Software):
        
        '''
        # 删除布局及控件
        while self.New_Starter_List_Layout.count():
            item = self.New_Starter_List_Layout.takeAt(0)
            
            widget = item.widget()
            print(widget)
            if widget is not None:
                widget.deleteLater()'''

        Software_Name = (Software["Software_Name"])
        Software_Path = (Software["Software_Path"])
        Software_Variables = (Software["EnvironmentVariables"])
        

        self.Starter_Basic_information_Layout = QtWidgets.QVBoxLayout()
        self.Starter_Basic_information_Layout.setObjectName(Software_Name + "_Starter_Basic_information_Layout")
        self.Software_horizontal_Layout = QtWidgets.QHBoxLayout()
        self.Software_horizontal_Layout.setObjectName(Software_Name + "_Software_horizontal_Layout")
        self.Software_Name_Button = QtWidgets.QPushButton(Software_Name)
        self.Software_Name_Button.setMinimumSize(QtCore.QSize(0, 30))
        self.Software_Name_Button.setObjectName(Software_Name)
        self.Software_horizontal_Layout.addWidget(self.Software_Name_Button)
        self.New_Variable_Button = QtWidgets.QPushButton("新建")
        self.New_Variable_Button.setMinimumSize(QtCore.QSize(30, 30))
        self.New_Variable_Button.setMaximumSize(QtCore.QSize(30, 30))
        self.New_Variable_Button.setObjectName(Software_Name + "_New_Variable_Button")
        self.Software_horizontal_Layout.addWidget(self.New_Variable_Button)
        self.Software_Del_Button = QtWidgets.QPushButton("删除")
        self.Software_Del_Button.setMinimumSize(QtCore.QSize(30, 30))
        self.Software_Del_Button.setMaximumSize(QtCore.QSize(30, 30))
        self.Software_Del_Button.setObjectName(Software_Name + "_Software_Del_Button")
        self.Software_horizontal_Layout.addWidget(self.Software_Del_Button)
        self.Software_horizontal_Layout.setStretch(0, 1)
        self.Starter_Basic_information_Layout.addLayout(self.Software_horizontal_Layout)
        self.Software_path_Layout = QtWidgets.QHBoxLayout()
        self.Software_path_Layout.setObjectName(Software_Name + "_Software_path_Layout")
        self.Software_Path_LineEdit = QtWidgets.QLineEdit(self.New_Starter_Widget)
        self.Software_Path_LineEdit.setObjectName(Software_Name + "_Software_Path_LineEdit")

        self.Software_Path_LineEdit.setText(Software_Path)

        self.Software_path_Layout.addWidget(self.Software_Path_LineEdit)
        self.Software_Path_Button = QtWidgets.QPushButton(self.New_Starter_Widget)
        self.Software_Path_Button.setObjectName(Software_Name + "_Software_Path_Button")
        self.Software_path_Layout.addWidget(self.Software_Path_Button)
        self.Starter_Basic_information_Layout.addLayout(self.Software_path_Layout)

        for count in range(len(Software_Variables)):
            #Software_Variable["Key"]
            self.read_Software_Variables_info(Software_Name,Software_Variables[count],str(count+3))

        self.New_Starter_List_Layout.addLayout(self.Starter_Basic_information_Layout)

        self.New_Variable_Button.clicked.connect(lambda *args: self.New_Variable())
        self.Software_Del_Button.clicked.connect(lambda *args: self.Software_Del())



    #读取软件环境变量
    def read_Software_Variables_info(self,Software_Name,Software_Variable,count):
        self.read_Software_info_delete(self.New_Starter_List_Layout)
        '''
        # 删除布局及控件
        while self.Starter_Basic_information_Layout.count():
            item = self.Starter_Basic_information_Layout.takeAt(0)
            widget = item.widget()
            if widget is not None:
                widget.deleteLater()'''


        self.Variable_horizontal_Layout = QtWidgets.QHBoxLayout()
        self.Variable_horizontal_Layout.setSizeConstraint(QtWidgets.QLayout.SizeConstraint.SetMinAndMaxSize)
        self.Variable_horizontal_Layout.setObjectName(Software_Name +"_" + count + "_Variable_horizontal_Layout")
        self.Variable_lineEdit = QtWidgets.QLineEdit(self.New_Starter_Widget)
        self.Variable_lineEdit.setObjectName(Software_Name +"_" + count + "_Key")
        self.Variable_lineEdit.setText(Software_Variable["Key"])

        self.Variable_horizontal_Layout.addWidget(self.Variable_lineEdit)
        self.Value_lineEdit = QtWidgets.QLineEdit(self.New_Starter_Widget)
        self.Value_lineEdit.setObjectName(Software_Name +"_" + count + "_Value")
        self.Value_lineEdit.setText(Software_Variable["Value"])


        self.Variable_horizontal_Layout.addWidget(self.Value_lineEdit)
        self.Del_Variable_Button = QtWidgets.QPushButton(count)
        self.Del_Variable_Button.setMinimumSize(QtCore.QSize(25, 25))
        self.Del_Variable_Button.setMaximumSize(QtCore.QSize(25, 25))
        self.Del_Variable_Button.setObjectName(Software_Name +"_" + count + "_Del_Variable_Button")
        self.Variable_horizontal_Layout.addWidget(self.Del_Variable_Button)
        self.Starter_Basic_information_Layout.addLayout(self.Variable_horizontal_Layout)
        self.Del_Variable_Button.clicked.connect(lambda *args: self.delete_layout())


############################################################创建###################################################################################
    #创建项目
    def __Project_New(self):
        text, ok = QInputDialog.getText(self, "新建项", "请输入新项的名称:")
        if ok:
            new_item = QListWidgetItem(text)
            new_item.setSizeHint(QtCore.QSize(180, 50))  # 设置按钮的高度为40
            font = new_item.font()
            font.setPointSize(14)  # 设置字体大小为14
            new_item.setFont(font)
            self.Project_en_lineEdit.setText(text)
            self.Project_Set_listWidget.addItem(new_item)

            import shutil
            shutil.copyfile("H:/QL_tool_file/Window_Tool/Logical File/SoftwareStarter/TEXT.json","H:/QL_tool_file/Window_Tool/Logical File/SoftwareStarter/Projecinfo/"+text+".json")



    ##创建新的项目模块
    def __New_Modile_lineEdit(self):
        self.NewModile_HBLayout = QtWidgets.QHBoxLayout()
        self.NewModile_HBLayout.setObjectName("NewModile_HBLayout")
        self.NewModile_line_edit = QtWidgets.QLineEdit(self.Project_Modile_info_widget)
        self.NewModile_line_edit.setObjectName("NewModile_line_edit")
        self.NewModile_HBLayout.addWidget(self.NewModile_line_edit)
        self.Del_modile_Button = QtWidgets.QPushButton(self.Project_Modile_info_widget)
        self.Del_modile_Button.setMinimumSize(QtCore.QSize(20, 20))
        self.Del_modile_Button.setMaximumSize(QtCore.QSize(20, 20))
        self.Del_modile_Button.setObjectName("Del_modile_Button")
        self.NewModile_HBLayout.addWidget(self.Del_modile_Button)

        row = self.Project_Modile_info_gridLayout.rowCount()  # 获取当前行数
        #print(row)
        column = 1  # 新的LineEdit总是放在第一列
        self.Project_Modile_info_gridLayout.addLayout(self.NewModile_HBLayout, row, column)  # 将LineEdit添加到下一行的第一列

    ##创建新的启动器
    def New_Software(self):
        text, ok = QInputDialog.getText(self, "启动器名称", "请输入新启动器名称:")
        if ok:
            self.Starter_Basic_information_Layout = QtWidgets.QVBoxLayout()
            self.Starter_Basic_information_Layout.setObjectName(text + "_Starter_Basic_information_Layout")
            self.Software_horizontal_Layout = QtWidgets.QHBoxLayout()
            self.Software_horizontal_Layout.setObjectName(text + "_Software_horizontal_Layout")
            self.Software_Name_Button = QtWidgets.QPushButton(text)
            self.Software_Name_Button.setMinimumSize(QtCore.QSize(0, 30))
            self.Software_Name_Button.setObjectName(text)
            self.Software_horizontal_Layout.addWidget(self.Software_Name_Button)
            self.New_Variable_Button = QtWidgets.QPushButton("新建")
            self.New_Variable_Button.setMinimumSize(QtCore.QSize(30, 30))
            self.New_Variable_Button.setMaximumSize(QtCore.QSize(30, 30))
            self.New_Variable_Button.setObjectName(text + "_New_Variable_Button")
            self.Software_horizontal_Layout.addWidget(self.New_Variable_Button)
            self.Software_Del_Button = QtWidgets.QPushButton("删除")
            self.Software_Del_Button.setMinimumSize(QtCore.QSize(30, 30))
            self.Software_Del_Button.setMaximumSize(QtCore.QSize(30, 30))
            self.Software_Del_Button.setObjectName(text + "_Software_Del_Button")
            self.Software_horizontal_Layout.addWidget(self.Software_Del_Button)
            self.Software_horizontal_Layout.setStretch(0, 1)
            self.Starter_Basic_information_Layout.addLayout(self.Software_horizontal_Layout)
            self.Software_path_Layout = QtWidgets.QHBoxLayout()
            self.Software_path_Layout.setObjectName(text + "_Software_path_Layout")
            self.Software_Path_LineEdit = QtWidgets.QLineEdit(self.New_Starter_Widget)
            self.Software_Path_LineEdit.setObjectName(text + "_Software_Path_LineEdit")
            self.Software_path_Layout.addWidget(self.Software_Path_LineEdit)
            self.Software_Path_Button = QtWidgets.QPushButton(self.New_Starter_Widget)
            self.Software_Path_Button.setObjectName(text + "_Software_Path_Button")
            self.Software_path_Layout.addWidget(self.Software_Path_Button)
            self.Starter_Basic_information_Layout.addLayout(self.Software_path_Layout)



            self.New_Starter_List_Layout.addLayout(self.Starter_Basic_information_Layout)
        
            
            self.New_Variable_Button.clicked.connect(lambda *args: self.New_Variable())
            self.Software_Del_Button.clicked.connect(lambda *args: self.Software_Del())
        else:
            pass

    #创建新的启动器环境变量
    def New_Variable(self):
        sender = self.sender()
        clickedList = sender.objectName().split("_")[0]
        for NewLauncher in self.starter_settings_widget.findChildren(QtWidgets.QGridLayout):
                if "New_Starter_Layout" in NewLauncher.objectName():
                    for New_QVBoxLayout  in  NewLauncher.findChildren(QtWidgets.QVBoxLayout):
                        for Starter_Basic_information_Layout  in  New_QVBoxLayout.findChildren(QtWidgets.QVBoxLayout):
                            Starter_Basic_information_Layoutset = New_QVBoxLayout.findChild(QVBoxLayout,clickedList + "_Starter_Basic_information_Layout")
                            if Starter_Basic_information_Layout == Starter_Basic_information_Layoutset:
                                count = str(Starter_Basic_information_Layout.count()+1)
                                print(count)

                                self.Variable_horizontal_Layout = QtWidgets.QHBoxLayout()
                                self.Variable_horizontal_Layout.setSizeConstraint(QtWidgets.QLayout.SizeConstraint.SetMinAndMaxSize)
                                self.Variable_horizontal_Layout.setObjectName(clickedList +"_" + count + "_Variable_horizontal_Layout")
                                self.Variable_lineEdit = QtWidgets.QLineEdit(self.New_Starter_Widget)
                                self.Variable_lineEdit.setObjectName(clickedList +"_" + count + "_Key")
                                self.Variable_horizontal_Layout.addWidget(self.Variable_lineEdit)
                                self.Value_lineEdit = QtWidgets.QLineEdit(self.New_Starter_Widget)
                                self.Value_lineEdit.setObjectName(clickedList +"_" + count + "_Value")
                                self.Variable_horizontal_Layout.addWidget(self.Value_lineEdit)
                                self.Del_Variable_Button = QtWidgets.QPushButton(count)
                                self.Del_Variable_Button.setMinimumSize(QtCore.QSize(25, 25))
                                self.Del_Variable_Button.setMaximumSize(QtCore.QSize(25, 25))
                                self.Del_Variable_Button.setObjectName(clickedList +"_" + count + "_Del_Variable_Button")
                                self.Variable_horizontal_Layout.addWidget(self.Del_Variable_Button)
        Starter_Basic_information_Layout.addLayout(self.Variable_horizontal_Layout)

        self.Del_Variable_Button.clicked.connect(lambda *args: self.delete_layout())

##########################################################删除########################################################################################
    #删除软件
    def Software_Del(self):
        sender = self.sender()
        clickedList = sender.objectName().split("_")[0]
        print(clickedList)
        #print(sender.objectName())
        layouts = self.starter_settings_widget.findChildren(QtWidgets.QGridLayout)
        #遍历 layouts 列表
        for layout in layouts:
            for New_Starter_List_Layout  in  layout.findChildren(QtWidgets.QVBoxLayout):
        
                if clickedList in New_Starter_List_Layout.objectName() and clickedList + "_Starter_Basic_information_Layout" == New_Starter_List_Layout.objectName():
                    self.delete_Launcher_layout(New_Starter_List_Layout)
    # 递归删除布局函数
    def delete_Launcher_layout(self,layout):
        print(layout.objectName())
        while layout.count():
            item = layout.takeAt(0)
            widget = item.widget()
            sublayout = item.layout()
            if widget is not None:
                widget.deleteLater()
            elif sublayout is not None:
                self.delete_Launcher_layout(sublayout)
                
        parent = layout.parentWidget()
        if parent is not None:
            parent.layout().removeItem(layout)
        del layout
        
    ###删除网格布局内的横向布局
    def delete_layout(self):
        sender = self.sender()
        name = (sender.objectName().split("_"))
        print(name[1])
        for NewLauncher in self.starter_settings_widget.findChildren(QtWidgets.QGridLayout):
                if "New_Starter_Layout" in NewLauncher.objectName():
                    for New_QVBoxLayout  in  NewLauncher.findChildren(QtWidgets.QVBoxLayout):
                        for Starter_Basic_information_Layout  in  New_QVBoxLayout.findChildren(QtWidgets.QVBoxLayout):
                            Starter_Basic_information_Layoutset = New_QVBoxLayout.findChild(QVBoxLayout,name[0] + "_Starter_Basic_information_Layout")
                            if Starter_Basic_information_Layout == Starter_Basic_information_Layoutset:
                                for i in range(Starter_Basic_information_Layout.count()):
                                    
                                    
                                    item = Starter_Basic_information_Layout.itemAt(i)
                                    
                                    if name[0] + "_" + name[1] in item.objectName():
                                        #print(item.objectName())
                                        #self.Software_info_delete(item)
                                        print(item)
                                        print(item.layout())
                                        layout = item.layout()
                                        # 删除布局中的控件
                                        while layout.count():
                                            item1 = layout.takeAt(0)
                                            if item1.widget():
                                                item1.widget().deleteLater()

                                        # 删除布局
                                        layout = None
                                        del layout

                                    #print(item.layout())
                                    
                                    # child_vbox_layout  = item.layout()
                                    # if name[1] in child_vbox_layout.objectName():
                                    #     self.Software_info_delete(child_vbox_layout)
                                    # print(Starter_Basic_information_Layout.objectName())
                                        
    def Software_info_delete(self,layout):
        while layout.count():
            item = layout.takeAt(0)
            widget = item.widget()
            sublayout = item.layout()
            if widget is not None:
                widget.deleteLater()
            elif sublayout is not None:
                self.delete_Launcher_layout(sublayout)
        
                
                                

    def read_Software_info_delete(self,layout):
        print(layout.objectName())
        while layout.count():
            item = layout.takeAt(0)
            widget = item.widget()
            sublayout = item.layout()
            if widget is not None:
                widget.deleteLater()
            elif sublayout is not None:
                self.delete_Launcher_layout(sublayout)
        

    #删除项目
    def __Project_Del(self):
        selectedItems = self.Project_Set_listWidget.selectedItems()
        for item in selectedItems:
            row = self.Project_Set_listWidget.row(item)
            self.Project_Set_listWidget.takeItem(row)

    def show_context_menu(self, pos):
        sender = self.sender()  # 获取发送信号的对象
        menu = QMenu(sender)
        delete_action = QAction("删除", self)
        delete_action.triggered.connect(lambda: self.delete_line_edit(sender))
        menu.addAction(delete_action)
        menu.exec_(sender.mapToGlobal(pos))

    def delete_line_edit(self, line_edit):
        if line_edit in self.line_edit_list:
            line_edit.deleteLater()
            self.line_edit_list.remove(line_edit)





    ####################################################内容区域折叠#################################################################################
    ################################################################################################################################################

    def __Project_Set_Visible(self):
        # 切换内容区域的可见性
        self.Project_info_widget.setVisible(not self.Project_info_widget.isVisible())

    def __Project_Modile_Visible(self):
        # 切换内容区域的可见性
        self.Project_Modile_info_widget.setVisible(not self.Project_Modile_info_widget.isVisible())

    def __Shot_Set_Visible(self):
        # 切换内容区域的可见性
        self.ShotFile_info_widget.setVisible(not self.ShotFile_info_widget.isVisible())

    def __Launcher_Settings_Visible(self):
        self.New_Starter_Widget.setVisible(not self.New_Starter_Widget.isVisible())


    ####################################################设置保存#################################################################################
    ############################################################################################################################################

    def __Project_Save_File(self):
        if len(self.Project_en_lineEdit.text()) <= 0:
            # 创建消息框对象
            msg_box = QMessageBox()
            # 设置消息框的标题和文本内容
            msg_box.setWindowTitle("提示")
            msg_box.setText("需填写项目中文名！")
            msg_box.exec_()
        else:
            Project_info = {}
            Project_set ={}
            Project_set["Project_en"] = self.Project_en_lineEdit.text()
            Project_set["Project_cn"] = self.Project_cn_lineEdit.text()
            Project_set["Start_Time"] = self.Start_Time_lineEdit.text()
            Project_set["Frame"] = self.Frame_lineEdit.text()
            Project_set["ImageHeight"] = self.ImageHeight_lineEdit.text()
            Project_set["ImageWidth"] = self.ImageWidth_lineEdit.text()
            Project_set["ImageScale"] = self.ImageScale_lineEdit.text()
            Project_set["Project_local_Path"] = self.Project_local_Path_lineEdit.text()
            Project_set["Project_Network_Path"] = self.Project_Network_Path_lineEdit.text()
            Project_set["Project_assets_Path"] = self.Project_assets_Path_lineEdit.text()
            Project_info["Project_set"] = Project_set
            Project_ModileList = []
            line_edits = self.Project_Modile_info_widget.findChildren(QtWidgets.QLineEdit)
            for line_edit in line_edits:
                # 处理每一个lineEdit
                # print(line_edit.text())
                Project_Modile = {}
                Project_Modile["ModileName"] = line_edit.text()
                Project_ModileList.append(Project_Modile)
            Project_info["Modile_set"] = Project_ModileList

            # line_edits = self.Shot_Set_widget.findChildren(QtWidgets.QLineEdit)
            # for line_edit in line_edits:
            #    # 处理每一个lineEdit
            #    # print(line_edit.text())

            Project_ShotList = []
            Project_Shot = {}
            Project_Shot["Set"] = self.Set_lineEdit.text()
            Project_Shot["Set_Split"] = self.Set_Split_lineEdit.text()
            Project_Shot["Events"] = self.Events_lineEdit.text()
            Project_Shot["Events_Split"] = self.Events_Split_lineEdit.text()
            Project_Shot["Lens"] = self.Lens_lineEdit.text()
            Project_Shot["Lens_Split"] = self.Lens_Split_lineEdit.text()
            Project_Shot["Class"] = self.Class_lineEdit.text()
            Project_Shot["Class_Split"] = self.Class_Split_lineEdit.text()
            Project_Shot["Version"] = self.Version_lineEdit.text()
            Project_Shot["VersionNumber"] = self.VersionNumber_lineEdit.text()
            Project_Shot["FileFormat"] = self.FileFormat_lineEdit.text()
            # Project_ShotList.append(Project_Shot)
            Project_info["Shot_set"] = Project_Shot



            Softwares = {}
            for NewLauncher_QVBoxLayout in self.starter_settings_widget.findChildren(QtWidgets.QGridLayout):
                for New_QVBoxLayout in NewLauncher_QVBoxLayout.findChildren(QtWidgets.QVBoxLayout):
                    if New_QVBoxLayout.objectName() == "New_Starter_List_Layout":
                        Software_List = []
                        for Starter_Basic_information_Layout in New_QVBoxLayout.findChildren(QtWidgets.QVBoxLayout):
                            Softwareinfo = {}
                            Software_Variable_List = [] # 每次循环都创建一个新的空列表
                            for QHBoxLayoutList in Starter_Basic_information_Layout.findChildren(QtWidgets.QHBoxLayout):
                                #print(QHBoxLayoutList.objectName)
                                                
                                for i in range(QHBoxLayoutList.count()):
                                    widget = QHBoxLayoutList.itemAt(i).widget()
                                    if isinstance(widget, QPushButton):
                                        if widget.text() == widget.objectName():

                                            Softwareinfo["Software_Name"] = widget.text()
                                    if isinstance(widget, QLineEdit):
                                        if "_Software_Path_LineEdit" in widget.objectName():
                                            Softwareinfo["Software_Path"] = widget.text()
                                
                                if "Variable_horizontal_Layout" in QHBoxLayoutList.objectName():
                                    print(QHBoxLayoutList.objectName())
                                    '''
                                    # 获取布局项
                                    Name = QHBoxLayoutList.itemAt(0)
                                    Value = QHBoxLayoutList.itemAt(1)
                                    Variable = {}
                                    Variable["Key"] = Name.widget().text()
                                    Variable["Value"] = Value.widget().text()
                                    Software_Variable_List.append(Variable)
                                
                                Softwareinfo["EnvironmentVariables"] = Software_Variable_List
                            Software_List.append(Softwareinfo)
            
            Project_info["Softwares"] = Software_List
            #print(Project_info)                     
        with open(self.ProjecinfoPath + self.Project_en_lineEdit.text() +'.json','w') as fp:
            json.dump(Project_info, fp, indent=4, sort_keys=False)'''



if __name__ == '__main__':
    app = QApplication([]) if not QApplication.instance() else None
    MWin = mainWindow()
    for qt in QApplication.topLevelWidgets():
        if qt.windowTitle() == u'mainWindow':
            qt.close()
    MWin.show()
    app.exec_() if app else None
